const state = {
  routeInfo: null, // 线路信息
  selectedIndex: -1, // 默认选中站点序号
  selectedStation: null // 默认选中站点信息
}

const getters = {
  routeInfo: state => state.routeInfo,
  selectedIndex: state => state.selectedIndex,
  selectedStation: state => state.selectedStation
}

const actions = {
  fetchRouteInfo: ({ commit, state }, text) => {
    commit('updateRouteInfo', text)
  },
  fetchSelectedIndex: ({ commit, state }, text) => {
    commit('updateSelectedIndex', text)
  },
  fetchSelectedStation: ({ commit, state }, text) => {
    commit('updateSelectedStation', text)
  }
}

const mutations = {
  updateRouteInfo: (state, payload) => {
    state.routeInfo = payload
  },
  updateSelectedIndex: (state, payload) => {
    state.selectedIndex = payload
  },
  updateSelectedStation: (state, payload) => {
    state.selectedStation = payload
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
